﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml.Packaging;
using OpenXmlPowerTools;
using System.IO;

namespace DbWord
{
    class Word
    {
        public void Build()
        {
            FileInfo fi =   new FileInfo(Defs.WordFile);
            File.Copy(Defs.WordFile, Path.Combine(
                fi.DirectoryName, fi.Name 
                + ParametersCache.Instance.InitDateTime.ToString("yyyyMMdd") 
                + "." 
                + fi.Extension));

            WordprocessingDocument word = WordprocessingDocument.Open("", true);
            // Test document generation from template("Test_Template - 1.docx")
            //DocumentGenerationInfo docinfo = GetDocInfo(
            //    " Openxml 2.0 builder ver 1.0",
            //    "1.0",
            //    null,
            //    Defs.WordFile,
            //    false);

            //MyDocGenerator myDocGenerator = new MyDocGenerator(docinfo);
            //myDocGenerator.RptTime = new DateTime(2014, 4, 14);

            //byte[] result = myDocGenerator.GenerateDocument();

            //// 去掉标签
            ////byte[] primaryDoc = File.ReadAllBytes(Defs.FinalPath);
            ////List<byte[]> otherDocs = new List<byte[]>();
            ////otherDocs.Add(result);
            ////OpenXmlHelper openXmlHelper = new OpenXmlHelper(DocumentGenerationInfo.NamespaceUri);
            ////byte[] result2 = openXmlHelper.AppendDocumentsToPrimaryDocument(primaryDoc, otherDocs);

            //WriteOutputToFile("tpl网管周报 20140422_debug.docx", "tpl网管周报 20140422.docx", result);

            string file = Path.Combine("tpl", "tpl网管周报 20140422_debug.docx");

            ChartHelper chartupdater = new ChartHelper();
            chartupdater.UpdateChart(file);


            Console.WriteLine("Finsih. Please Press Enter to continue...");
            Console.ReadLine();
        }
    }
}
